package com.wenan.data
{
	import com.adobe.serialization.json.JSON;
	import com.wenan.AppGlobal;
	
	import flash.utils.Dictionary;
	
	import mx.collections.ArrayCollection;
	
	public class UserInfo
	{
		private var _id:String;
		private var _username:String;
		private var _email:String;
		private var _truename:String;//真实名
		private var _remarks:String;//职位
		private var _defaultpage:PageInfo;//首页
		private var _appkey:String;//密钥
		private var _purviews:Dictionary = new Dictionary();//权限
		
		public function UserInfo()
		{
		}
		
		public function get id():String
		{
			return _id;
		}
		
		public function set id(value:String):void
		{
			_id = value;
		}
		
		public function get username():String
		{
			return _username;
		}
		
		public function set username(value:String):void
		{
			_username = value;
		}
		
		public function get email():String
		{
			return _email;
		}
		
		public function set email(value:String):void
		{
			_email = value;
		}
		
		public function get truename():String
		{
			return _truename;
		}
		
		public function set truename(value:String):void
		{
			_truename = value;
		}
		
		public function get remarks():String
		{
			return _remarks;
		}
		
		public function set remarks(value:String):void
		{
			_remarks = value;
		}
		
		public function get defaultpage():PageInfo
		{
			if(!_defaultpage)
			{
				var countryParameters:ParameterCollection = new ParameterCollection();
				countryParameters.add(new Parameter("navIndex","0"));
				countryParameters.add(new Parameter("navName","全国"));
				
				_defaultpage = new PageInfo("CountryNavigator", "0", "全国", PositionType.GLOBAL,countryParameters);
			}
			return _defaultpage;
		}
		
		public function set defaultpage(value:PageInfo):void
		{
			_defaultpage = value;
		}
		
		public function get appkey():String
		{
			return _appkey;
		}
		
		public function set appkey(value:String):void
		{
			_appkey = value;
		}
		
		public function get purviews():Dictionary
		{
			return _purviews;
		}
		
		public function createUserInfo(result:Object):void
		{
			id = result.id;
			truename = result.truename;
			username = result.username;
			email = result.email;
			appkey = result.appkey;
			remarks = result.remarks;
			
			var pageInfo:PageInfo;
			
			if(result.defaultpage)
			{
				pageInfo = createPageInfo(result.defaultpage);
				defaultpage = pageInfo;
				
				if(result.defaultpage.pageInfos != null)
				{
					AppGlobal.createPageInfos(result.defaultpage.pageInfos as Array);
				}
			}
			else
			{
			}
			
			purviews["purview_mainshop"] = result.purview_mainshop;
			purviews["purview_org"] = result.purview_org;
			purviews["purview_page"] = result.purview_page;
			purviews["purview_shop"] = result.purview_shop;
			
		}
		
		public function createPageInfo(result:Object):PageInfo
		{
			if(!result) return null;
			
			var pageName:String = result.pageName;
			var positionId:String = result.positionId;
			var positionName:String = result.positionName;
			var positionType:int = result.positionType;
			
			var parameters:ParameterCollection = new ParameterCollection();
			var parameter:Parameter;
			
			var parameterList:Array = result.parameters as Array;
			for(var i:int=0;i<parameterList.length;i++)
			{
				if (parameterList[i].obj)
				{
					parameter = new Parameter(parameterList[i].name, null, new ArrayCollection(parameterList[i].obj as Array));
				} else 
				{
					parameter = new Parameter(parameterList[i].name,parameterList[i].value);
				}
				parameters.add(parameter);
			}
			
			var pageInfo:PageInfo = new PageInfo(pageName,positionId,positionName,positionType,parameters);
			
			return pageInfo;
		}
		
	}
}